package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JdbcTest {

	public static void main(String[] args) throws ClassNotFoundException {
		String url = "jdbc:mysql://localhost:3306/manager?allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMT";
		String username = "student";
		String password = "st_123456";
		  Connection con;
		  Class.forName("com.mysql.cj.jdbc.Driver");
		  try {
			con = DriverManager.getConnection(url, username, password);
			Statement sta = con.createStatement();
			ResultSet rs = sta.executeQuery("select * from student");
			
			while(rs.next()) {
				int numCount = rs.getMetaData().getColumnCount();
				StringBuffer buffer = new StringBuffer();
				buffer.append("\nStudent:{\n");
				for(int i = 1;i<numCount;i++) {
					buffer.append("\t"+rs.getMetaData().getColumnLabel(i) + ":" + rs.getObject(i) + "\n");
				}
				buffer.append("}");
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
